package cn.wolfcode.rocketmq._02_message_type;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

public class Producer2 {

    public static void main(String[] args) throws Exception{

        //创建生产者对象,并指定生产者组
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("wolfcode-producer");

        //设置超时时间
        defaultMQProducer.setSendMsgTimeout(10000);

        //设置名字服务的地址
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");

        //启动生产者
        defaultMQProducer.start();

        //创建一个消息
        Message message = new Message("03_message_type","hello,RocketMQ!".getBytes("utf-8"));

        //发送消息
        defaultMQProducer.sendOneway(message);

        //关闭生产者连接
        defaultMQProducer.shutdown();


    }
}
